home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_flame.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.2 KB  |  74 lines

  1. /*
  2.  * flame.sl -- RenderMan compatible surface shader for a flame-like texture.
  3.  *
  4.  * DESCRIPTION:
  5.  *    Makes something that looks like fire.
  6.  *
  7.  * PARAMETERS:
  8.  *    distortion - 
  9.  *    chaosscale, chaosoffset, octaves - control the fBm
  10.  *    flameheight, flameamplitude - scaling factors
  11.  *
  12.  * ANTIALIASING:
  13.  *    None, but should be easy to add antialiasing simply by adaptively
  14.  *    setting the "octaves" parameter based on distance from eye point.
  15.  *
  16.  * AUTHOR:
  17.  *    C language version by F. Kenton Musgrave
  18.  *    Translation to RenderMan Shading Language by Larry Gritz.
  19.  *
  20.  * REFERENCES:
  21.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  22.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  23.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  24.  *
  25.  * HISTORY:
  26.  *    ??? - original C language version by Ken Musgrave
  27.  *    Apr 94 - translation to Shading Language by L. Gritz
  28.  *
  29.  * this file last updated 18 Apr 1994
  30.  */
  31.  
  32. #define snoise(p) (2 * float noise(p) - 1)
  33. #define DNoise(p) (2 * (point noise(p)) - point(1, 1, 1))
  34. #define VLNoise(p, scale) (snoise(p + scale * DNoise(p)))
  35.  
  36. surface k3d_flame(float distortion = 0;
  37.           float chaosscale = 1; float chaosoffset = 0;
  38.           float octaves = 7; float flameoffset = 0.0;
  39.           float flameamplitude = 2.0; float phase = 0.0)
  40. {
  41.   point PP, PQ;
  42.   float freq;
  43.   float chaos, i, cmap;
  44.  
  45.   PP = point(s, t, phase);
  46.   PQ = PP;
  47.   PQ *= point(1, 1, exp(-ycomp(PP)));
  48.   freq = 1;
  49.   chaos = 0;
  50.   for(i = 0; i < octaves; i += 1)
  51.     {
  52.       chaos += VLNoise(freq * PQ, distortion) / freq;
  53.       freq *= 2;
  54.     }
  55.  
  56.   chaos = abs(chaosscale * chaos + chaosoffset);
  57.   cmap = 0.85 * chaos + flameoffset + (flameamplitude * ycomp(PP));
  58.   Ci =
  59.     Cs * color spline(cmap, color(0, 0, 0), color(0, 0, 0), color(27, 0, 0),
  60.               color(54, 0, 0), color(81, 0, 0), color(109, 0, 0),
  61.               color(136, 0, 0), color(166, 5, 0), color(189, 30, 0),
  62.               color(211, 60, 0), color(231, 91, 0), color(238, 128,
  63.                                   0),
  64.               color(244, 162, 12), color(248, 187, 58), color(251,
  65.                                       209,
  66.                                       115),
  67.               color(254, 236, 210), color(255, 241, 230), color(255,
  68.                                     241,
  69.                                     230))
  70.     / 255;
  71.  
  72.   Oi = 0.001;
  73. }
  74.